package com.diandiji.demo.controller;

import com.diandiji.demo.entity.Accountbook;
import com.diandiji.demo.entity.User;
import com.diandiji.demo.service.AccountbookService;
import com.diandiji.demo.service.UserService;
import com.diandiji.demo.vo.AccountbookListVO;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.ZoneId;

@RestController
@RequestMapping("/account/book")
public class AccountbookController {

    @Resource
    private AccountbookService accountbookService;


    // 根据年月查询账本数据
    @GetMapping("/list")
    public AccountbookListVO queryByMonth(@RequestParam String date) {
        return accountbookService.queryByMonth(date);
    }

    // 添加账本
    @PostMapping("/add")
    public Accountbook add(@RequestBody Accountbook accountbook) {
        return accountbookService.add(accountbook);
    }

    // 删除账本
    @DeleteMapping("/del/{id}")
    public String deleteById(@PathVariable Integer id) {
        accountbookService.deleteById(id);
        return "删除账本成功，账本ID：" + id;
    }

    // 更新账本
    @PostMapping("/update")
    public String update(@RequestBody Accountbook accountbook) {
        accountbookService.update(accountbook);
        return "更新账本成功，账本ID：" + accountbook.getId();
    }

}
